package org.ricks.game.config;

import org.ricks.ioc.anno.Bean;
import org.ricks.ioc.anno.Configuration;
import org.ricks.orm.OrmContext;
import org.ricks.orm.accessor.MongodbAccessor;
import org.ricks.orm.config.CacheStrategy;
import org.ricks.orm.config.HostConfig;
import org.ricks.orm.config.OrmConfig;
import org.ricks.orm.config.PersisterStrategy;
import org.ricks.orm.manager.OrmManager;
import org.ricks.orm.query.MongodbQuery;

import java.util.List;

@Configuration
public class OrmAutoConfiguration {


    @Bean
    public OrmManager ormManager() {
        OrmConfig ormConfig = new OrmConfig();
        HostConfig hostConfig = HostConfig.valueOf("chess_ricks",
                "admin","",
                null,
                "admin");
        ormConfig.setHost(hostConfig);
        ormConfig.setEntityPackage("org.ricks.game");
        ormConfig.setCaches(List.of(CacheStrategy.DEFAULT));
        ormConfig.setPersisters(List.of(PersisterStrategy.DEFAULT));
        ormConfig.setId("ormManager");
        return new OrmManager(ormConfig);
    }


    @Bean
    public MongodbAccessor mongodbAccessor() {
        return new MongodbAccessor();
    }

    @Bean
    public MongodbQuery mongodbQuery() {
        return new MongodbQuery();
    }


    @Bean
    public OrmContext ormContext() {
        return new OrmContext();
    }
}
